package loginController

import (
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/sessions"
	"iristest/common/res"
	"iristest/service/loginService"
)

type Controller struct {
	ils loginService.ILoginService
}

func New() *Controller {
	return &Controller{
		ils: loginService.New(),
	}
}

func (c *Controller) GetLoginIs(ctx iris.Context) res.Result {
	//if sessions.Get(ctx).Get("token") == nil {
	//	return res.NoLogin()
	//}
	return res.Success(true)
}

func (c *Controller) PostLogin(ctx iris.Context) res.Result {
	return c.ils.Login(ctx)
}
func (c *Controller) GetExit(ctx iris.Context) res.Result {
	rs := sessions.Get(ctx).Delete("token")
	return res.Success(rs)
}

func (c *Controller) PostRegister(ctx iris.Context) res.Result {
	return c.ils.Register(ctx)
}
